#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QPainter>
#include <QPoint>
#include <QVector>
#include <chess_pieces.h>
#include <QTcpSocket>
#include <QMouseEvent>
#include <QLabel>
#include <QMovie>
#include <QVBoxLayout>
#include "chess_pieces.h"
#include "win_losser.h"



typedef struct _Change_//走子信息
{
    ChessInfo chess;
    Position target_pos;
} Change;

enum CmdType//命令类型
{
    ChangeChess = 0,
    Cat_effectively,
    Cat_uneffectively,
    Red_cmd,
    Black_cmd,
    Win,
    Fail
};

typedef struct _ComData//命令结构体
{
    int type_cmd;
    Change change;
} ComData;



class Widget : public QWidget
{
    Q_OBJECT
public slots:

public:
    Widget(QString ip,int port, QWidget *parent = nullptr);
    ~Widget();

    void paintEvent(QPaintEvent *event);
    void mousePressEvent(QMouseEvent *event);

    void set_ske(int skex,int skey,QString filepatn);//设置偏移量和图片

    void initCheckerboard(QVector<chess_pieces> &red, QVector<chess_pieces> &black);

public slots:
    void recvMSG();


private:
    double l_left;//左边框
    double l_right;//有边框
    double l_top;//上边框
    double l_down;//下边框

    double skex;//x偏移量
    double skey;//y偏移量
    QString filepath;//文件路径
    QPixmap background;//棋盘

    QLabel *wait_label_img;

    QMovie *movie;

    //点击鼠标位置，（虚拟值）
    QPoint posfirst;

    QVector<chess_pieces> red;
    QVector<chess_pieces> black;

    //通信套接字 和服务器通信
    QTcpSocket *socket_com;

    int CAMP=-1;

    //标记第几次点击，0表示未点击，1表已有棋子被选中
    int xuanzhongflag=0;

    //第二次记录的坐标
    QPoint possecend;

    chess_pieces *select_chess=nullptr;


    //允许走步
    bool Allowed_run=false;

    //更新棋子信息
    int changeChessboard(QVector<chess_pieces> &action_camp, QVector<chess_pieces> &Waiting_camp, const ComData *data);

    win_losser *loss;
    win_losser *win;


};
#endif // WIDGET_H
